// 用户中心相关接口
/**
 * 请求回调
 * @callback requestCallback
 * @param {object} data 请求回调的数据
 */
export default {
	getProjectTreeAllByUserSync(params = {}) {
		let key = `CT.ProjectTreeAllByUser.${User.getUser().userId}.${params.menuCode}`;
		let data = CallBack.get(key);
		if (data) return data;
		params.brandId = BrandUtil.getGlobalBrand().brandId;
		data =
			SyncHttp.getData({
				url: "bd/project/tree/user",
				data: params
			}).data || [];
		if (ListUtil.hasLength(data)) {
			let format = function(list) {
				for (var i = 0; i < list.length; i++) {
					let item = list[i];
					item.label = item.projectName;
					item.value = item.projectId;
					if (item.children) format(item.children);
				}
			};
			format(data);
		}
		CallBack.set(key, data);
		return nlapp.TreeUtil.removeEmptyChildren(data);
	},
	/**
	 * 获取省市 UC0208
	 * @param {object} opt
	 * @param {object} opt.data 请求入参
	 * @param {requestCallback} [opt.success] 用户名称
	 * @param {requestCallback} [opt.complete] 请求完成回调
	 */
	queryAreaList(opt = {}) {
		Http.callService({
			url: "uc/dict/area/tree",
			data: opt.data || {}
		})
			.success((data) => {
				opt.success && opt.success(data);
			})
			.complete((data) => {
				opt.complete && opt.complete(data);
			});
	},
	/**
	 * 员工-模糊查询-用于员工搜索下拉框 UC2048
	 * @param {object} opt
	 * @param {object} opt.data 请求入参
	 * @param {string} [opt.data.eeWorkstatus] 员工在职状态 O:在职;L:离职;W:预入职
	 * @param {string} [opt.data.userName] 员工姓名
	 * @param {requestCallback} [opt.success] 请求成功回调
	 * @param {requestCallback} [opt.complete] 请求完成回调
	 */
	queryUserList(opt = {}) {
		Http.callService({
			url: "uc/ee/list/forsearch",
			data: opt.data || {}
		})
			.success((data) => {
				opt.success && opt.success(data);
			})
			.complete((data) => {
				opt.complete && opt.complete(data);
			});
	}
};
